package com.gy.api.pc.sys.log.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.Constants;
import com.gy.api.base.R;
import com.gy.api.base.RestPage;
import com.gy.api.pc.sys.log.domain.vo.SysLogSearchVO;
import com.gy.api.pc.sys.log.domain.vo.SysLogVO;
import com.gy.api.pc.sys.log.service.ISysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api( tags = ApiIndex.SysLogController)
@RequestMapping(value = "/sys/log")
@RestController
@SaCheckLogin
public class SysLogController {

    @Autowired
    private ISysLogService service;

    @ApiOperation(value = "查询系统操作日志列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<SysLogVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute SysLogSearchVO searchVO) {
        List<SysLogVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation(value = "查询系统模块列表")
    @GetMapping(value = "/module_list")
    public R<List<String>> module_list() {
        return new R(Constants.SYS_LOG_MODULE);
    }


    @ApiOperation(value = "清理所有系统操作日志")
    @PostMapping(value = "/clear")
    public R clear() {
        service.clear();
        return new R();
    }

}
